package com.yuandian.business.monitor.controller;

import com.yuandian.api.business_monitor.po.SqlAnalysisParams;
import com.yuandian.api.business_monitor.vo.SqlAnalysisVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.business.monitor.service.ISqlAnalysisService;
import com.yuandian.utils.PageDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 慢sql分析
 *
 * @author zhoutian
 * @date 2020/12/8 14:43
 */
@RestController
@Api(value = "sqlAnalysis", tags = "慢sql分析接口")
@RequestMapping("/analysis/sql")
public class SqlAnalysisController {

    @Autowired
	ISqlAnalysisService sqlAnalysisService;


    /**
     * 获取图表信息
     *
     * @param params 	请求参数
     * @return		结果集
     */
    @GetMapping("/getMap")
	@ApiOperation(value = "慢sql分析-获取图表信息", notes = "慢sql分析-获取图表信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "currentTime",  	value = "当前时间",  			  paramType = "query",  required = true,    dataType = "String"),
			@ApiImplicitParam(name = "timePiece", 	 	value = "时间段 如7：【7-8】小时",   paramType = "query",  required = true,    dataType = "String"),
			@ApiImplicitParam(name = "size",   		 	value = "查询数量大小", 			  paramType = "query",  required = true,    dataType = "Integer"),
			@ApiImplicitParam(name = "pageNum",   	 	value = "页码", 					  paramType = "query",  required = true,    dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 	 	value = "每页大小", 			      paramType = "query",  required = true,    dataType = "Long")
	})
    public R<List<SqlAnalysisVo>> getMap(SqlAnalysisParams params) {
        return sqlAnalysisService.getSqlAnalysisList(params);
    }


    /**
     * 获取图表信息
     *
     * @param params	请求参数
     * @return		结果集
     */
    @GetMapping("/getDetail")
	@ApiOperation(value = "慢sql分析-sql详情列表", notes = "慢sql分析-sql详情列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "currentTime", 	value = "当前时间",  			  paramType = "query",  required = true,   dataType = "String"),
			@ApiImplicitParam(name = "timePiece", 		value = "时间段 如7：【7-8】小时",   paramType = "query",  required = true,   dataType = "String"),
			@ApiImplicitParam(name = "size",   			value = "查询数量大小", 			  paramType = "query",  required = true,   dataType = "Integer"),
			@ApiImplicitParam(name = "pageNum",   		value = "页码", 					  paramType = "query",  required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 		value = "每页大小", 			      paramType = "query",  required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "orderByColumn", 	value = "排序字段", 				  paramType = "query",  required = true,   dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 			value = "升降序:ASC，DESC",  	  paramType = "query",  required = true,   dataType = "String")
	})
	public R<PageDataInfo> getDetail(SqlAnalysisParams params) {
        return R.ok(sqlAnalysisService.getSqlAnalysisDetails(params));
    }

}
